package com.tanhua.server.controller;


import com.tanhua.server.service.LingHunService;
import com.tanhua.server.vo.ErrorResult;
import com.tanhua.server.vo.LingHunQv;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("peachblossom")
public class LingHunController {

    @Autowired
    private LingHunService lingHunService;

    //发送语音
    @PostMapping
    public ResponseEntity<Object> lingHunCun(@RequestParam("soundFile") MultipartFile file,
                                             @RequestHeader("Authorization") String token){
        try {
            Boolean bool = this.lingHunService.save(file,token);
            if (bool) {
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        ErrorResult errorResult = ErrorResult.builder().errCode("000001").errMessage("发送语音失败！").build();
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(errorResult);
    }

    //接收语音
    @GetMapping
    public LingHunQv lingHunQv(){


        LingHunQv lingHunQv= this.lingHunService.find();
        return lingHunQv;
    }
}
